#include <QPainter>
#include <QStyle>
#include <QStyleOption>

#include "ribbonbar.h"

/*---------------------------------*/

RibbonToolButton::RibbonToolButton()
{
    setToolButtonStyle(Qt::ToolButtonTextUnderIcon );
    setIconSize(QSize(32,32));
    setFixedHeight(64);
}



/*---------------------------------*/
RibbonAction::RibbonAction(const QString &txt, const QString &toolTip,const QIcon& icn)
{
    setText(txt);
    setIcon(icn);
    setToolTip(toolTip);
}

/*---------------------------------*/

RibbonToolButtonGroup::RibbonToolButtonGroup(QGroupBox* parent) : QGroupBox(parent)
{
    layout = new QGridLayout;
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(0);

    setLayout(layout);
}

void RibbonToolButtonGroup::addToolBtn(RibbonToolButton* btn)
{
    if(btn)
    {
        layout->addWidget(btn, 0, nCnt);
        ++nCnt;
    }

}

void RibbonToolButtonGroup::addToolBtn(QToolButton* btn)
{
    if(btn)
    {
        layout->addWidget(btn, 0, nCnt);
        ++nCnt;
    }
}

void RibbonToolButtonGroup::addCheckBox(QCheckBox* check)
{
    if(check)
    {
        layout->addWidget(check, 0, nCnt);
        ++nCnt;
    }
}


/*---------------------------------*/
RibbonToolBar::RibbonToolBar(const QString &_name,QWidget *parent) : QWidget(parent),
    name(_name)
{
    layout = new QHBoxLayout;
    layout->setMargin(1);
    layout->setSpacing(1);
    setLayout(layout);


}

void RibbonToolBar::addRibbonGroup(RibbonToolButtonGroup* gp)
{
    layout->addWidget(gp, 0, Qt::AlignLeft);
    lBtnGroup.push_back(gp);
}

/*---------------------------------*/
RibbonBar::RibbonBar(QTabWidget *parent) : QTabWidget(parent)
{
    setContentsMargins(0,0,0,0);
    setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

}

void RibbonBar::addRibbonToolBar(RibbonToolBar* rtb)
{
    if(rtb) {
        addTab(rtb, rtb->getName());
        ltoolBtnBar.push_back(rtb);
    }

}


void RibbonBar::addRibbonToolButtonGroup(RibbonToolBar *toolbar,
                              RibbonToolButtonGroup *group)
{
    if(toolbar && group)
        toolbar->addRibbonGroup(group);
}

void RibbonBar::addRibbonToolButton(RibbonToolBar *toolbar,
                         RibbonToolButtonGroup *group,
                         RibbonToolButton *ribbonToolButton)
{
    if(toolbar && group && ribbonToolButton)
        group->addToolBtn(ribbonToolButton);
}
/*
void RibbonBar::paintEvent(QPaintEvent* e)
{
    Q_UNUSED(e)
    QStyleOption opt;
    opt.init(this);
    QPainter p(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

*/



